import { getToken } from 'util/token'
import { getUserInfo } from 'api/user'

const user = {
  state: {
    userInfo: {},
    token: getToken()
  },
  mutations: {
    SET_USER_INFO: (state, userInfo) => {
      state.userInfo = userInfo
    }
  },
  actions: {
    GetUserInfo({commit, state}) {
      getUserInfo(state.token).then(data => {
        commit('SET_USER_INFO', data)
      })
    }
  }
}

export default user
